package org.boot.fast.core.api.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.boot.fast.core.api.service.DynamicSqlService;
import org.boot.fast.dao.entity.FastApiConfigDO;
import org.boot.fast.dao.service.FastApiConfigService;
import org.boot.fast.pojo.CommonResult;
import org.boot.fast.pojo.PageResult;
import org.boot.fast.util.CollUtil;
import org.boot.fast.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

import static org.boot.fast.pojo.CommonResult.success;

@Tag(name = "动态接口生成器")
@RestController
@SuppressWarnings("all")
@RequestMapping("/fast/generate")
public class GenerateApiController {

    @Autowired
    private FastApiConfigService fastApiConfigService;


    @PostMapping("/api/allGenerate")
    @Operation(summary = "生成指定表的所有目前支持接口")
    public CommonResult<List<FastApiConfigDO>> generateAllApi(@RequestParam("version") String version,
                                                              @RequestParam("table") String table,
                                                               @RequestParam("sysModule") String sysModule) {
        List<FastApiConfigDO> fastApiConfigDOList = fastApiConfigService.generateAllApi(version, table, sysModule);
        return success(fastApiConfigDOList);
    }

    @PostMapping("/api/insertGenerate")
    @Operation(summary = "生成指定表的插入接口")
    public CommonResult<FastApiConfigDO> generateInsertApi(@RequestParam("version") String version,
                                                           @RequestParam("table") String table,
                                                           @RequestParam("apiKey") String apiKey,
                                                           @RequestParam("sysModule") String sysModule) {
        FastApiConfigDO fastApiConfigDO = fastApiConfigService.generateInsertApi(version, table, apiKey, sysModule);
        return success(fastApiConfigDO);
    }

    @PostMapping("/api/insertBatchGenerate")
    @Operation(summary = "生成指定表的批量插入接口")
    public CommonResult<FastApiConfigDO> generateInsertBatchApi(@RequestParam("version") String version,
                                                               @RequestParam("table") String table,
                                                               @RequestParam("apiKey") String apiKey,
                                                                @RequestParam("sysModule") String sysModule) {
        FastApiConfigDO fastApiConfigDO = fastApiConfigService.generateInsertBatchApi(version, table, apiKey, sysModule);
        return success(fastApiConfigDO);
    }
     @PostMapping("/api/updateGenerate")
    @Operation(summary = "生成指定表的更新接口")
    public CommonResult<FastApiConfigDO> generateUpdateApi(@RequestParam("version") String version,
                                                           @RequestParam("table") String table,
                                                           @RequestParam("apiKey") String apiKey,
                                                           @RequestParam("sysModule") String sysModule) {
        FastApiConfigDO fastApiConfigDO = fastApiConfigService.generateUpdateApi(version, table, apiKey, sysModule);
        return success(fastApiConfigDO);
    }

    @PostMapping("/api/deleteGenerate")
    @Operation(summary = "生成指定表的删除接口")
    public CommonResult<FastApiConfigDO> generateDeleteApi(@RequestParam("version") String version,
                                                           @RequestParam("table") String table,
                                                           @RequestParam("apiKey") String apiKey,
                                                           @RequestParam("sysModule") String sysModule) {
        FastApiConfigDO fastApiConfigDO = fastApiConfigService.generateDeleteApi(version, table, apiKey, sysModule);
        return success(fastApiConfigDO);
    }

    @PostMapping("/api/deleteBatchGenerate")
    @Operation(summary = "生成指定表的批量删除接口")
    public CommonResult<FastApiConfigDO> generateDeleteBatchApi(@RequestParam("version") String version,
                                                               @RequestParam("table") String table,
                                                               @RequestParam("apiKey") String apiKey,
                                                                @RequestParam("sysModule") String sysModule) {
        FastApiConfigDO fastApiConfigDO = fastApiConfigService.generateDeleteBatchApi(version, table, apiKey, sysModule);
        return success(fastApiConfigDO);
    }

    @PostMapping("/api/queryGenerate")
    @Operation(summary = "生成指定表的查询接口")
    public CommonResult<FastApiConfigDO> generateQueryApi(@RequestParam("version") String version,
                                                           @RequestParam("table") String table,
                                                           @RequestParam("apiKey") String apiKey,
                                                          @RequestParam("sysModule") String sysModule) {
        FastApiConfigDO fastApiConfigDO = fastApiConfigService.generateQueryApi(version, table, apiKey, sysModule);
        return success(fastApiConfigDO);
    }

}
